package action.admin.assignment;

import beans.Assignment;
import dao.MngAssignment;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class updateAssign extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String assign_name = request.getParameter("assign_name");
            String class_id = request.getParameter("class_id");
            String create_date = request.getParameter("create_date");
            String finish_date = request.getParameter("finish_date");
            MngAssignment mngAssign = new MngAssignment();
            List<Assignment> listAssign = mngAssign.showAssignByClass(class_id);
            for (Assignment assign : listAssign) {
                assign.setAssign_id(assign.getAssign_id());
                assign.setAssign_name(assign_name);
                assign.setCreate_date(create_date);
                assign.setFinish_date(finish_date);
                mngAssign.updateAssign(assign);
            }
            String msg = "Update assign successful !";
            request.setAttribute("msg", msg);
            request.setAttribute("class_id", class_id);
            request.setAttribute("assign_name", assign_name);
            RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=showassign");
            rd.forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
